package com.hzgj.soa.spring.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Created by ye.pan on 2015/6/10.
 */
@Component
public class Client {

    @Autowired(required = false)
    private obj.INumberService NumberService;

    public void invoke1() throws InterruptedException {

        for (int i = 0; i < 30; i++) {
            final int finalI = i;
            new Thread(() -> {
                while (true) {
                    inn(finalI);
                }
            }).start();
//            in(i);
        }
//        NumberService.setNextNumber(123);
    }

    public void inn(int i) {
        try {
            TimeUnit.MILLISECONDS.sleep(1000);
//            System.out.println(NumberService.getObject(i));
            NumberService.GetNextNumber(new int[]{2, 3});
        } catch (Exception e) {
            e.printStackTrace();
        }
//                    System.out.println(NumberService.GetNextNumber(123));

    }

    public void invoke() throws InterruptedException {

//        for (int i = 0; i < 10; i++) {
//            final int finalI = i;
//            new Thread(() -> {
//                while (true) {
//                    in(finaWlI);
//                }
//            }).start();
////            in(i);
//        }
        System.out.println(NumberService.getIt(123).size());
    }

    public void in(int i) {
        try {
            TimeUnit.MILLISECONDS.sleep(1000);
//            System.out.println(NumberService.getObject(i));
            NumberService.GetNextNumber(new int[]{i, i + 1, i + 2, i + 3});
        } catch (Exception e) {
            e.printStackTrace();
        }
//                    System.out.println(NumberService.GetNextNumber(123));

    }
}
